﻿<%@ Page Title="Contact" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Contact.aspx.cs" Inherits="IP_PROJECT.Contact" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <hgroup class="title">
        <h1><%: Title %>.</h1>
    </hgroup>

    <section class="contact">
        <asp:Repeater ID="ContactRepeater" runat="server" DataSourceID="ContactDataSource">
            <ItemTemplate>
                <asp:LoginView id="UserView" runat="server">
                    <RoleGroups>
                        <asp:RoleGroup Roles="Admin">
                            <ContentTemplate>
                                <p>
                                    <asp:TextBox ID="Id" runat="server" Text='<%# Eval("Id") %>' Visible="False" />
                                    <asp:TextBox ID="KeyInput" runat="server" Text='<%# Eval("Key") %>' MaxLength="50" />
                                    <asp:TextBox ID="ValueInput" runat="server" Text='<%# Eval("Value") %>'/>
                                    <asp:Button ID="FieldDelete" runat="server" Text="Delete" CommandArgument='<%# Eval("Id") %>' OnClick="FieldDelete_Click" />
                                </p>
                            </ContentTemplate>
                        </asp:RoleGroup>
                        <asp:RoleGroup Roles="General">
                            <ContentTemplate>
                                <p><b><%# Eval("Key") %>:</b> <%# Eval("Value") %></p>
                            </ContentTemplate>
                        </asp:RoleGroup>
                    </RoleGroups>
                    <AnonymousTemplate>
                        <p><b><%# Eval("Key") %>:</b> <%# Eval("Value") %></p>
                    </AnonymousTemplate>
                </asp:LoginView>
            </ItemTemplate>
        </asp:Repeater>
        <asp:LoginView id="SaveView" runat="server">
                    <RoleGroups>
                        <asp:RoleGroup Roles="Admin">
                            <ContentTemplate>
                                <p> 
                                    <asp:TextBox ID="KeyInput" runat="server"/>
                                    <asp:TextBox ID="ValueInput" runat="server"/>
                                </p>
                                <p><asp:Button ID="SaveContacts" runat="server" Text="Save" OnClick="SaveContacts_Click" /></p>
                            </ContentTemplate>
                        </asp:RoleGroup>
                    </RoleGroups>
        </asp:LoginView>
        <asp:SqlDataSource runat="server" ID="ContactDataSource" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT [Id], [Key], [Value] FROM [Map] WHERE ([View] = @View)">
            <SelectParameters>
                <asp:Parameter DefaultValue="Contact" Name="View" Type="String"></asp:Parameter>
            </SelectParameters>
        </asp:SqlDataSource>
    </section>
</asp:Content>